﻿Imports System.IO

Partial Class WebUserControls_CntlImageViewer
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If String.IsNullOrEmpty(Request.QueryString("Album")) OrElse String.IsNullOrEmpty(Request.QueryString("Luogo")) Then
                Response.Redirect("~/Default.aspx")

            Else

                CaricaRepeater()
            End If
            Dim Keywords As New HtmlMeta
            Keywords.Name = "keywords"
            Keywords.Content = Request.QueryString("Album") & Request.QueryString("Album").Replace(" ", ",") & Request.QueryString("Luogo") & Request.QueryString("Luogo").Replace(" ", ",")
            Page.Header.Controls.Add(Keywords)

            Dim Description As New HtmlMeta
            Description.Name = "Description"
            Description.Content = "Galleria immagini " & Request.QueryString("Luogo") & " " & Request.QueryString("Album")
            Page.Header.Controls.Add(Description)
        End If
    End Sub

    
    Public Sub CaricaRepeater()
        Dim di As DirectoryInfo = New DirectoryInfo(Server.MapPath("/"))
        Dim dirPath As String = ""
        If (Not String.IsNullOrWhiteSpace(Request.QueryString("Luogo"))) AndAlso Request.QueryString("Luogo").IndexOf("ScopriPadova") >= 0 Then

            dirPath = di.FullName & "localimages\ScopriPadova\" & Request.QueryString("Luogo").Replace("ScopriPadova_", "") & "\" & Request.QueryString("Album")
        Else
            dirPath = di.FullName & "localimages\" & Request.QueryString("Luogo") & "\" & Request.QueryString("Album")
        End If

        ' Path.Combine(Radice, Request.QueryString("Locale"), Request.QueryString("Album"))
        '  Throw New Exception(dirPath)
        If (Not System.IO.Directory.Exists(dirPath)) Then
            Exit Sub
        End If
        'Throw New Exception(dirPath)
        Page.Title = Request.QueryString("Album").Replace("_", " ") & " - " & Request.QueryString("Luogo")
        Dim ImagesFileName() As String = System.IO.Directory.GetFiles(Path.Combine(dirPath))
        ' Throw New Exception(String.Join(",", ImagesFileName))
        Dim aList As New List(Of String)
        Dim li As String = ""
        For Each str As String In ImagesFileName
            li = str.Replace(di.FullName, "Http://padovado.it/").Replace("\", "/")
            aList.Add(li)
        Next
        ' Throw New Exception(String.Join(",", aList))
        RptImages.DataSource = aList
        RptImages.DataBind()
        '    SelectedImage.ImageUrl = aList(0)
    End Sub

End Class
